package com.cta.dao;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.cta.dao.impl.BasePersistenceImpl;

@Repository("reportPersistence")
public class ReportPersistence extends BasePersistenceImpl implements BasePersistence {

	@SuppressWarnings("rawtypes")
	public List<Object[]> loadAllContactPbx(List<Long> ids) {
		StringBuffer sql = new StringBuffer("in (");
		for (int i = 1; i <= ids.size(); i++) {
			if (i == ids.size()) {
				sql.append("?" + i + ")");
			} else {
				sql.append("?" + i + ", ");
			}
		}
		String rSql = String
				.format("select c.name as text, c.id as obId, c.assign_to as parentId, 'contact' as type from cta_contact c where c.assign_to %s " +
						"union select p.name as text, p.id as obId, p.assign_to as parentId, 'pbx' as type from cta_pbx p where p.assign_to %s",
						sql.toString(), sql.toString());
		return getListWithNativeSql(rSql, ids.toArray());
	}

}
